import Vue from 'vue';

/**
 * @param {time} 秒数
 * @param {type} 不传-返回年月日, 1-返回年月日时分秒,
 */
Vue.filter('formatTime', (time, type) => {
    let date = new Date(time);
    let Y = date.getFullYear();
    let M = date.getMonth() + 1;
    let D = date.getDate();
    let h = date.getHours();
    let m = date.getMinutes();
    let s = date.getSeconds();
    M = M < 10 ? "0" + M : M;
    D = D < 10 ? "0" + D : D;
    h = h < 10 ? "0" + h : h;
    m = m < 10 ? "0" + m : m;
    s = s < 10 ? "0" + s : s;


    if (type === 1) {
        return `${Y}-${M}-${D} ${h}:${m}:${s}`;
    } else {
        // 默认
        return `${Y}-${M}-${D}`;
    }
})